package com.qfjy.controller;

import com.qfjy.entity.po.MeetingPub;
import com.qfjy.service.MeetingPubService;
import com.qfjy.util.resulst.ResultCode;
import com.qfjy.util.resulst.ResultJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName MeetingPubController
 * @Description TODO 微信端
 * @Author guoweixin
 * @Date 2022/8/10
 * @Version 1.0
 */
@RequestMapping("meetingPub")
@Controller
@Slf4j
public class MeetingPubController {

    @Autowired
    private MeetingPubService meetingPubService;

    @GetMapping("select")
    @ResponseBody
    public Object select(@RequestParam("id")String id){

       MeetingPub meetingPub= meetingPubService.selectByPrimaryKey(id);

       if(meetingPub==null){
           return  new ResultJson<>(null, ResultCode.NOT_DATA);
       }

        return  new ResultJson<>(meetingPub,ResultCode.SUCCESS) ;
    }


    /**
     * TODO 根据会议编号查找会议信息 ,调用视频微服务（获取视频相关信息）
     * url: meetingPub/get?pcode=111
     */
    @GetMapping("get")
    @ResponseBody
    public Object selectMeetingPubByPcode(@RequestParam("pcode") String pcode){
        MeetingPub meetingPub=meetingPubService.selectMeetingPubByPcode(pcode);
        if(meetingPub==null){
            return  new ResultJson<>(null, ResultCode.NOT_DATA);
        }

        //调用 视频微服务--》通过RestTemplate模版实现  得到视频信息
        /**
         * param1 url 请求的URL地址
         * param2 responseType 希望返回的类型.class
         * param3 占位符 最后一个参数是map,map的key为前面的占位符。map value为参数值
         * 可变长度的参数，一一来替换前面的占位符 name={name}形式，
         */
        String url="http://localhost:8085/videoInfo/get?pcode="+meetingPub.getPcode();
        String result= restTemplate.getForObject(url,String.class);

        log.info("视频微服务间通信调用："+result);

        meetingPub.setRemark(result);

        return  new ResultJson<>(meetingPub,ResultCode.SUCCESS) ;
    }

    @Autowired
    private RestTemplate restTemplate;






}
